from utils.api_util import Session


class LoginTool:
    '''
    登陆工具类:提供抢租客登录功能、出租方登录功能、平台方登录功能
    '''
    session = Session.get_session()

    @classmethod
    def get_cookie(cls):
        '''
        使用者请忽略这个方法
        通过发送image请求来获取cookie
        :return:
        '''
        url = "http://192.168.12.138:8080/SharedParkingPlace/image"
        cls.session.get(url=url)

    @classmethod
    def login(cls, data):
        '''
        使用者请忽略这个方法
        使用指定的数据完成登录
        :param data:
        :return:
        '''
        cls.get_cookie()
        url = "http://192.168.12.138:8080/SharedParkingPlace/login"
        resp = cls.session.get(url=url, params=data)
        print(resp.text)
        return cls.session

    @classmethod
    def login_qiangzuke(cls):
        '''
        使用抢租客角色进行登录
        :return:
        '''
        data = {"uname":"抢租客0","upass":"123","imgcode":"0000"}
        cls.login(data)

    @classmethod
    def login_chuzufang(cls):
        '''
        使用出租方角色进行登录
        :return:
        '''
        data = {"uname": "出租方1", "upass": "123", "imgcode": "0000"}
        cls.login(data)

    @classmethod
    def login_pt(cls):
        '''
        使用平台方角色进行登录
        :return:
        '''
        data = {"uname": "pt", "upass": "123", "imgcode": "0000"}
        cls.login(data)


if __name__ == '__main__':
    # LoginTool.login_qiangzuke()
    # LoginTool.login_chuzufang()
    LoginTool.login_pt()